#include<stdio.h>
#include<string.h>

//实现mycat
//cat myfile.txt

int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        printf("Usage: %s filename\n", argv[0]);
        return 1;
    }

    FILE *fp = fopen(argv[1], "r");
    if(!fp)
    {
        perror("fopen:");
        return 2;
    }

    while(1)
    {
        char buffer[128];
        memset(buffer, 0, sizeof(buffer));
        //读取文件
        //fread函数返回实际读取的元素数量
        int n = fread(buffer, sizeof(buffer)-1, 1, fp);
        if(n > 0)
        {
            printf("%s", buffer);
        }
        //判断文件结束feof
        if(feof(fp))
            break;
    }

    fclose(fp);

    return 0;
}
